﻿using SM;
using System;

namespace TestSM
{
    class Program
    { 
        static void Main(string[] args)
        {
            var pair = SMUtil.GenerateKeyPair();
            Console.WriteLine("公钥:" + pair.PublicKey);
            Console.WriteLine("私钥:" + pair.PrivateKey);


            var publicKey = "04630CE36F44941CBC439C40DF23C06092F3803BA84867D4F0B95E01BA46691BD51893B00E1B4801433CDD1103004EA2F473A63D02BD1EBCB53D4E62ED2760F5F0";
            var privateKey = "009DAB777B879485B71B556B16B983FD6022BAA3525B3562123C6A4CC0245DAEDA";

            var originalData = "这是原文";
            // SM2 公钥加密
            var sm2EncryptedData = SMUtil.Sm2Encrypt(publicKey, originalData);
            Console.WriteLine("SM2 公钥加密后的数据：" + sm2EncryptedData);

            // SM2 私钥解密
            var sm2DecryptedData = SMUtil.Sm2Decrypt(privateKey, sm2EncryptedData);
            Console.WriteLine("SM2 私钥解密后的数据：" + sm2DecryptedData);

            // SM2 签名
            var signature = SMUtil.Sign(originalData, privateKey);
            Console.WriteLine("SM2 签名：" + signature);

            // SM2 验签
            var isVerified = SMUtil.Verify(originalData, signature, publicKey);
            Console.WriteLine("SM2 验签结果：" + isVerified);

            // SM3 摘要算法
            var md = SMUtil.Sm3Encrypt(originalData);
            Console.WriteLine("SM3 摘要：" + md);

            // SM4 块加密算法-加密
            var key = "0123456789ABCDEF";
            var sm4EncryptedData = SMUtil.Sm4Encrypt(originalData, key);
            Console.WriteLine("SM4 块加密算法-加密后的数据：" + sm4EncryptedData);

            // SM4 块加密算法-解密
            var sm4DecryptedData = SMUtil.Sm4Decrypt(sm4EncryptedData, key);
            Console.WriteLine("SM4 块加密算法-解密后的数据：" + sm4DecryptedData);

            Console.ReadLine();
        }
    }
}
